<?php

class rates_ctrl extends Controller
{


    //////每一个都进行单个提交

    public function __construct()
    {
        parent::__construct();

    }

    /************************* 评价管理 *****************************/

    #region 获取数据库里的评价(此方法存在问题,前台不需要使用获取评价的接口,要进行修正)
    public function get_rates()
    {
        if (!$this->ajax_err) {
            $_mdl = Loader::mdl('traderate_mdl');
            $itemId = $_REQUEST["itemId"];
            $data = $_mdl->get_one($itemId);

            $data['content'] = json_decode($data['content']);
            $data['tags'] = json_decode($data['tags']);

            $this->ajax($data);
        } else {
            return $this->ajax('', array(1, '未登录', 1, '请登录'));
        }
    }

    #region 设置评价
    public function set_content()
    {
        if (!$this->ajax_err && $this->uid) {
            $item_id = $_REQUEST["item_id"];
            $content = $_REQUEST["content"];
            //$content['description'] = json_encode($content['description']);
            $_mdl = Loader::mdl('traderate_mdl');
            $data = $_mdl->set_content($item_id, addslashes($content));

            $this->ajax($data);
        } else {
            return $this->ajax('', array(1, '未登录', 1, '请登录'));
        }
    }
    #endregion

    #region 设置标签
    public function set_tags()
    {
        if (!$this->ajax_err && $this->uid) {
            $item_id = $_REQUEST["item_id"];
            $tags = $_REQUEST["tags"];
            $_mdl = Loader::mdl('traderate_mdl');
            $data = $_mdl->set_tags($item_id, addslashes($tags));

            $this->ajax($data);
        } else {
            return $this->ajax('', array(1, '未登录', 1, '请登录'));
        }
    }
    #endregion

}